import { Injectable } from '@nestjs/common';
// import { ConfigService } from '@nestjs/config';
import { Classification } from './classification.entity';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { PagingResponse } from 'src/constants/common.constants';
import { AppClassificationListDto } from './dto/list.dto';
// import { PassThrough } from 'stream';
@Injectable()
export class AppClassificationService {
  private access_token: string;
  private expires_in: number;
  private timestamp: number;

  constructor(
    @InjectRepository(Classification)
    private readonly appClassificationRepository: Repository<Classification>,
  ) {}

  async find(
    params: AppClassificationListDto,
  ): Promise<PagingResponse<Classification>> {
    console.log('params', params);
    // console.log(
    //   this.configService.get('DATABASE_HOST'),
    //   this.configService.get('database.host'),
    //   await this.cacheManager.get('key'),
    //   await this.userRepository.findAndCount({
    //     where: {
    //       ...params.params,
    //     },
    //   }),
    // );
    const [items, total] = await this.appClassificationRepository.findAndCount({
      // where: {
      //   ...params.params,
      // },
    });
    const { pageSize, pageNum } = params;
    return {
      records: items,
      total,
      pageSize,
      current: pageNum,
      pages: Math.ceil(total / pageSize),
    };
    // const [items] = await this.appClassificationRepository.findAndCount({});
    // return items;
    // return await this.userRepository
    //   .createQueryBuilder()
    //   .where({ deleted: 0 })
    //   .select(['user_name', 'email'])
    //   .getMany();
    //   .find();
  }

  async findAll(): Promise<Classification[]> {
    // console.log(
    //   this.configService.get('DATABASE_HOST'),
    //   this.configService.get('database.host'),
    //   await this.cacheManager.get('key'),
    //   await this.userRepository.findAndCount({
    //     where: {
    //       ...params.params,
    //     },
    //   }),
    // );
    const [items] = await this.appClassificationRepository.findAndCount({
      // where: {
      //   ...params.params,
      // },
    });
    return items;
    // const [items] = await this.appClassificationRepository.findAndCount({});
    // return items;
    // return await this.userRepository
    //   .createQueryBuilder()
    //   .where({ deleted: 0 })
    //   .select(['user_name', 'email'])
    //   .getMany();
    //   .find();
  }

  async findOne(id: number) {
    return await this.appClassificationRepository.findOne({
      where: {
        id,
      },
    });
  }
}
